package com.kadron.common;

import java.io.Serializable;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.contexts.Contexts;

import com.kadron.enumeration.DiscountType;
import com.kadron.enumeration.Gender;
import com.kadron.enumeration.KLang;

@AutoCreate
@BypassInterceptors
@Name("kUtilProvider")
@Scope(ScopeType.APPLICATION)
public class KUtilProvider implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5492919439447320887L;

	public Gender[] getGenders() {
		return Gender.values();
	}

	public KLang[] langs() {
		return KLang.values();
	}

	public DiscountType[] discountTypes() {
		return DiscountType.values();
	}

	public String getLang(String code) {
		if (KUtil.isEmpty(code)) {
			return getLang();
		}
		return KLang.valueOf(code).getMessage();
	}

	public String getLang() {
		String klang = (String) Contexts.getSessionContext().get("klang");
		if (KUtil.isEmpty(klang)) {
			klang = KLang.EN.toString();
			Contexts.getSessionContext().set("klang", klang);
		}
		return klang;
	}

}
